home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / amos / jwindows.lha / AllGadgets.asc < prev    next >
Text File  |  1996-04-25  |  8KB  |  227 lines

  1. '********************************************************************
  2. '* 
  3. '*     All Gadgets 2 
  4. '* 
  5. '********************************************************************
  6.  
  7. '   This program expands on the original AllGadgets program by making
  8. 'all the gadgets do something. This mainly entails connecting various
  9. 'gadgets so that they effect each other. 
  10. '   For example, the listview gadget has been connected to the string gadget 
  11. 'below it to allow you to change the entries in the listview, and the  
  12. 'checkboxes now disable various other gadgets, but there are many other
  13. 'features, so have a play. 
  14.  
  15. '   This mainly demonstrates how easy it can be to set up an interesting 
  16. 'program from a GadToolsBox framework. It also shows how to use the
  17. 'J Set Gadget Data command, along with the J Gadget Number/String commands 
  18. '(though for v39 upwards, it is more correct to use J Get Gadget Data).  
  19.  
  20. '   To help show how it was constructed, the changes made have been written
  21. 'below.
  22.  
  23. '   Changes made:
  24. '
  25. '      A handler has been added to interconnect the gadgets, this is in the
  26. '   wait loop. To do the actual processing, the _HANDLEGADGETS procedure has 
  27. '   been added.
  28. '      The global variable _LISTSEL has been added to keep track of which item 
  29. '   of the listview gadget has been selected.
  30. '      The size of the strings defined for the listview gadget in the _GUIDATA 
  31. '   routine have been set to a standard length of 30. This is the same as the
  32. '   maximum string length for the attached string gadget. This allows us to  
  33. '   edit the strings safely without the worry of writing out of the end of the 
  34. '   string.
  35. '      The global variable MYASL has been added. Code for creating a file
  36. '   requester has been placed before the events loop, and a line to remove 
  37. '   it in the cleanup routine
  38. '      The global variables DIS1-4 have been added to track which gadgets
  39. '   are disabled.
  40. Global _SCRAPTAGS,SCRAPTAGS,_PORTLIST,_MESSLIST
  41. Global PATH$,OSVER
  42. Global FHEIGHT,FWIDTH,MBAR,OX,OY,SW,SH
  43. Dim _GADGETSLABELS(1,9)
  44. Global _GADGETSLABELS()
  45. Dim _GADGETSSTRINGS(1)
  46. Global _GADGETSSTRINGS()
  47. Dim _GADGETSLISTS(1)
  48. Global _GADGETSLISTS()
  49. Dim _GADGETSGADS(19)
  50. Global _GADGETSGADS()
  51. Global _BUTTON1,_BUTTON2,_BUTTON3,_FILESTRING,_FILEGADGET,_CYCLE,_TEXT,_PALETTE,_SLIDER,_MX,_SCROLLER,_LISTVIEW,_LISTSTRING,_CBOX1,_CBOX2,_CBOX3,_CBOX4,_INTEGER,_NUMBER
  52. Dim _GADGETSZOOM(1)
  53. Global _GADGETSZOOM()
  54. Global _GADGETSWIND
  55.  
  56. '** this is used to record the selected item in the listview 
  57.  
  58. Global _LISTSEL
  59. _LISTSEL=-1
  60.  
  61. '** this is used for the asl file requester  
  62.  
  63. Global MYASL
  64.  
  65. '** these track whether certain gadgets are disabled 
  66. '  DIS1 is the file gadget, DIS2 is the palette
  67. '  DIS3 is the number gadget, DIS4 is other 3 check boxes
  68.  
  69. Global DIS1,DIS2,DIS3,DIS4
  70.  
  71. On Error Proc _CLEANUP
  72. _INITIALIZE
  73. _GUIDATA
  74. _SETUPALL
  75. _SETPORTS
  76.  
  77. '** here we create the file requester, with a few appropriate tags.
  78. 'Note that this is done AFTER opening the window otherwise ASLFR_Window
  79. 'would be rather pointless.
  80. 'Remember to add a J Free Asl Requester line to the _CLEANUP routine 
  81.  
  82. J Tag _SCRAPTAGS,1,Equ("ASLFR_TitleText"),J Make String("Select a file")
  83. J Tag Equ("ASLFR_SleepWindow"),True
  84. J Tag Equ("ASLFR_Window"),_GADGETSWIND
  85. J Tag Equ("ASLFR_RejectIcons"),True
  86. J Tag 0,0
  87. MYASL=J Create Asl Requester(Equ("ASL_FileRequest"),_SCRAPTAGS)
  88.  
  89. Do 
  90.    K=J Wait Message
  91.    While K
  92.       C=J Tag Data(_MESSLIST,1)
  93.       If C=Equ("IDCMP_CLOSEWINDOW")
  94.          _CLEANUP
  95.       Else If C=Equ("IDCMP_REFRESHWINDOW")
  96.          _DOREFRESH
  97.       Else If C=Equ("IDCMP_GADGETDOWN") or C=Equ("IDCMP_GADGETUP") or C=Equ("IDCMP_MOUSEMOVE")
  98.          _HANDLEGADGETS
  99.       End If 
  100.       K=J Next Message
  101.    Wend 
  102. Loop 
  103.  
  104. '** this procedure actually controls the gadgets. It's not as complex
  105. '   as it might at first seem
  106.  
  107. Procedure _HANDLEGADGETS
  108.    On Error Proc _CLEANUP
  109.    
  110.    'these two connect the scroller to the mx gadget 
  111.    If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_SCROLLER)
  112.       J Tag SCRAPTAGS,1,Equ("GTMX_Active"),J Tag Data(_MESSLIST,2)
  113.       J Tag 0,0
  114.       J Set Gadget Data _GADGETSGADS(_MX),_GADGETSWIND,SCRAPTAGS
  115.       
  116.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_MX)
  117.       J Tag SCRAPTAGS,1,Equ("GTSC_Top"),J Tag Data(_MESSLIST,2)
  118.       J Tag 0,0
  119.       J Set Gadget Data _GADGETSGADS(_SCROLLER),_GADGETSWIND,SCRAPTAGS
  120.       
  121.       'this connects the integer to the number gadget
  122.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_INTEGER)
  123.       J Tag SCRAPTAGS,1,Equ("GTNM_Number"),J Gadget Number(_GADGETSGADS(_INTEGER))*20
  124.       J Tag 0,0
  125.       J Set Gadget Data _GADGETSGADS(_NUMBER),_GADGETSWIND,SCRAPTAGS
  126.       
  127.       'these two connect the slider and the palette
  128.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_PALETTE)
  129.       J Tag SCRAPTAGS,1,Equ("GTSL_Level"),J Tag Data(_MESSLIST,2)
  130.       J Tag 0,0
  131.       J Set Gadget Data _GADGETSGADS(_SLIDER),_GADGETSWIND,SCRAPTAGS
  132.       
  133.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_SLIDER)
  134.       J Tag SCRAPTAGS,1,Equ("GTPA_Color"),J Tag Data(_MESSLIST,2)
  135.       J Tag 0,0
  136.       J Set Gadget Data _GADGETSGADS(_PALETTE),_GADGETSWIND,SCRAPTAGS
  137.       
  138.       'this connects the cycle to the text 
  139.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_CYCLE)
  140.       J Tag SCRAPTAGS,1,Equ("GTTX_Text"),_GADGETSLABELS(0,J Tag Data(_MESSLIST,2))
  141.       J Tag 0,0
  142.       J Set Gadget Data _GADGETSGADS(_TEXT),_GADGETSWIND,SCRAPTAGS
  143.       
  144.       'this records which listview item is selected
  145.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_LISTVIEW)
  146.       _LISTSEL=J Tag Data(_MESSLIST,2)
  147.       
  148.       'this changes an item in the listview
  149.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_LISTSTRING)
  150.       If _LISTSEL<>-1
  151.          'find the string to be changed from  the list
  152.          S=J Node Name(J Find Node(_GADGETSLISTS(0),_LISTSEL+1))
  153.          'change it 
  154.          J Change String S,J Read String$(J Gadget String(_GADGETSGADS(_LISTSTRING)))
  155.          'update the gadget (otherwise the change doesn't appear) 
  156.          J Tag SCRAPTAGS,1,Equ("GTLV_Labels"),_GADGETSLISTS(0)
  157.          J Tag 0,0
  158.          J Set Gadget Data _GADGETSGADS(_LISTVIEW),_GADGETSWIND,SCRAPTAGS
  159.       End If 
  160.       
  161.       'this brings up a file requester and puts the result in the string 
  162.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_FILEGADGET)
  163.       F$=J File Request$(MYASL,0)
  164.       If F$<>""
  165.          J Tag SCRAPTAGS,1,Equ("GTST_String"),Varptr(F$)
  166.          J Tag 0,0
  167.          J Set Gadget Data _GADGETSGADS(_FILESTRING),_GADGETSWIND,SCRAPTAGS
  168.       End If 
  169.       
  170.       'these benale functions control the buttons
  171.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_BUTTON1)
  172.       J Beep 
  173.       
  174.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_BUTTON2)
  175.       Boom 
  176.       
  177.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_BUTTON3)
  178.       Shoot 
  179.       
  180.       'disable the file string and button
  181.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_CBOX1)
  182.       Add DIS1,1,0 To 1
  183.       J Tag SCRAPTAGS,1,Equ("GA_Disabled"),DIS1
  184.       J Tag 0,0
  185.       J Set Gadget Data _GADGETSGADS(_FILESTRING),_GADGETSWIND,SCRAPTAGS
  186.       J Set Gadget Data _GADGETSGADS(_FILEGADGET),_GADGETSWIND,SCRAPTAGS
  187.       
  188.       'disable the palette and slider
  189.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_CBOX2)
  190.       Add DIS2,1,0 To 1
  191.       J Tag SCRAPTAGS,1,Equ("GA_Disabled"),DIS2
  192.       J Tag 0,0
  193.       J Set Gadget Data _GADGETSGADS(_PALETTE),_GADGETSWIND,SCRAPTAGS
  194.       J Set Gadget Data _GADGETSGADS(_SLIDER),_GADGETSWIND,SCRAPTAGS
  195.       
  196.       'disable the integer gadget
  197.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_CBOX3)
  198.       Add DIS3,1,0 To 1
  199.       J Tag SCRAPTAGS,1,Equ("GA_Disabled"),DIS3
  200.       J Tag 0,0
  201.       J Set Gadget Data _GADGETSGADS(_INTEGER),_GADGETSWIND,SCRAPTAGS
  202.       
  203.       'disable the first 3 checkboxes
  204.    Else If J Tag Data(_MESSLIST,4)=_GADGETSGADS(_CBOX4)
  205.       Add DIS4,1,0 To 1
  206.       J Tag SCRAPTAGS,1,Equ("GA_Disabled"),DIS4
  207.       J Tag 0,0
  208.       J Set Gadget Data _GADGETSGADS(_CBOX1),_GADGETSWIND,SCRAPTAGS
  209.       J Set Gadget Data _GADGETSGADS(_CBOX2),_GADGETSWIND,SCRAPTAGS
  210.       J Set Gadget Data _GADGETSGADS(_CBOX3),_GADGETSWIND,SCRAPTAGS
  211.    End If 
  212.    
  213. End Proc
  214.  
  215. 'these procedures are all from the GadToolsBox program, though _GUIDATA and
  216. '_CLEANUP have had minor changes as detailed above.
  217.  
  218. Procedure _INITIALIZE
  219. Procedure _SETUPALL
  220. Procedure _GUIDATA
  221. Procedure _MAKEGADGETSGADS
  222. Procedure _MAKEGADGETSWIND[SC]
  223. Procedure _DOREFRESH
  224. Procedure _SETPORTS
  225. Procedure _FREEWIND[W,G,M,A,C]
  226. Procedure _CLEANUP
  227.